﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using Metro.Core;

namespace Clock
{
    //public class Widget : Metro.Core.IWidget
    //{
    //    private WidgetControl _widgetControl;
    //    public static Settings Sett;
    //    public static Widget Instance;
    //    public static LocaleManager LocaleManager;

    //    public Widget()
    //    {
    //        Instance = this;
    //    }

    //    public string GetWidgetName()
    //    {
    //        return "Clock";
    //    }

    //    public UserControl Load()
    //    {
    //        Sett = Settings.Read(E.ConfigDirectory + "\\Clock.conf");

    //        LocaleManager = new LocaleManager(E.Path + "\\Clock\\Localization");
    //        LocaleManager.LoadLocale(E.Locale);

    //        _widgetControl = new WidgetControl();
    //        Grid.SetColumn(_widgetControl, Sett.Col);
    //        Grid.SetRow(_widgetControl, Sett.Row);
    //        _widgetControl.Load();
    //        return _widgetControl;
    //    }

    //    public void UpdateSettings()
    //    {
    //        _widgetControl.UpdateSettings();
    //    }

    //    public UserControl GetWidgetControl()
    //    {
    //        return _widgetControl;
    //    }

    //    public void Unload()
    //    {
    //        Sett.Write(E.ConfigDirectory + "\\Clock.conf");
    //    }

    //    public string GetIcon()
    //    {
    //        return E.Path + "\\Clock\\Resources\\icon.png";
    //    }

    //    public Point GetPosition()
    //    {
    //        return new Point(Sett.Col, Sett.Row);
    //    }

    //    public void SetPosition(int x, int y)
    //    {
    //        Sett.Col = x;
    //        Sett.Row = y;
    //    }

    //    public void AddMenuItem(MenuItem item)
    //    {
    //        AddContextMenuItem(item);
    //    }

    //    public event AddContextMenuItemHandler AddContextMenuItem;
    //    public event SetBgBrushHandler SetBgBrush;
    //}

    public class Widget : Metro.Core.Widget
    {
        private WidgetControl _widgetControl;
        public Settings Sett;
        public static Widget Instance;
        public LocaleManager LocaleManager;

        public Widget()
        {
            Instance = this;
        }

        public override string Name
        {
            get { return "Clock"; }
        }

        public override UserControl WidgetControl
        {
            get { return _widgetControl; }
        }

        public override string IconPath
        {
            get { return E.Path + "\\Clock\\Resources\\icon.png"; ; }
        }

        public override Point Position
        {
            get { return new Point(Sett.Col, Sett.Row); }
            set
            {
                Sett.Col = (int)value.X;
                Sett.Row = (int)value.Y;
            }
        }

        public override bool HasHub
        {
            get { return true; }
        }

        public override UserControl HubControl
        {
            get { return new HubControl(); }
        }

        public override void Load()
        {
            Sett = Settings.Read(E.ConfigDirectory + "\\Clock.conf");

            LocaleManager = new LocaleManager(E.Path + "\\Clock\\Localization");
            LocaleManager.LoadLocale(E.Locale);

            _widgetControl = new WidgetControl();
            Grid.SetColumn(_widgetControl, Sett.Col);
            Grid.SetRow(_widgetControl, Sett.Row);
            _widgetControl.Load();
        }

        public override void Unload()
        {
            Sett.Write(E.ConfigDirectory + "\\Clock.conf");
        }

        public void UpdateSettings()
        {
            _widgetControl.UpdateSettings();
        }

        public void AddMenuItem(MenuItem item)
        {
            AddContextMenuItem(item);
        }

        public override event AddContextMenuItemHandler AddContextMenuItem;
        public override event SetBgBrushHandler SetBgBrush;
    }
}
